﻿@model IEnumerable<MvcBoard.Models.Post>

@{
    ViewBag.Title = "Board List";
    var nPage = ViewBag.Page;
    //http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
}

@using PagedList.Mvc;
@using PagedList;

<link href="/Content/PagedList.css" rel="Stylesheet" type="text/css" />

<h2>Index</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>

<table class="tbl_list">
    <tr>
        <th style="width: 10%;">@Html.ActionLink("글번호", "Index", new { page = ViewBag.page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = "postNo" }, new { @style = "color:white; text-decoration:none;" })</th>
        <th style="width: 55%;">@Html.ActionLink("제목", "Index", new { page = ViewBag.page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = "subject" }, new { @style = "color:white;text-decoration:none;" })</th>
        <th style="width: 10%;">@Html.ActionLink("글쓴이", "Index", new { page = ViewBag.page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = "writer" }, new { @style = "color:white;text-decoration:none;" })</th>
        <th style="width: 15%;">@Html.ActionLink("작성일", "Index", new { page = ViewBag.page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = "writetime" }, new { @style = "color:white;text-decoration:none;" })</th>
        <th style="width: 10%;">@Html.ActionLink("조회수", "Index", new { page = ViewBag.page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = "readcount" }, new { @style = "color:white;text-decoration:none;" })</th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>@item.postNo</td>        
        <td style="text-align: left; padding-left: 15px;"><a href="/Board/Details/@item.postNo">@item.subject</a></td>
        <td>@item.name</td>
        <td>@item.writetime</td>
        <td>@item.readCount</td>
    </tr>
}
</table>

<div style="text-align:right">
@using (Html.BeginForm())
{
    <p> @Html.RadioButton("searchChoice", "writer", ViewBag.searchChoice == "writer" ? 1 : 0) 작성자 @Html.RadioButton("searchChoice", "subject", ViewBag.searchChoice == "subject" ? 1 : 0) 제목 @Html.RadioButton("searchChoice", "content", ViewBag.searchChoice == "content" ? 1 : 0) 내용 &nbsp;&nbsp;
        @Html.TextBox("SearchString")  
        @Html.ValidationMessage("SearchString")  
        <input type="submit" value="Search" onclick="return Search();"/></p>        
}
        <script type="text/javascript">
        //자바스크립트를 이용한 밸리데이션 체크방법
            function Search() {
                if(document.getElementById("SearchString").value == '')
                {
                    alert('검색어를 입력해주세요');
                    document.getElementById("SearchString").focus();
                    return false;
                }
            }
        </script>

</div>

@section scripts{
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">
    //<![CDATA[
        $(document).ready(function () {
            $('tr').has('td').hover(function () {
                $(this).css('background', '#f5f5f5');
            }, function () {
                $(this).css('background', '#fff');
            });

            //$('tr').has('td').on('click', function () {
            //    location.href = "/Board/Details/" + $(this).children('td').first().text();
            //});

            //$('tr').has('td').css('cursor', 'pointer');
        });    
        // ]]>    
    </script>
}

     <div style="text-align:center">
        @Html.PagedListPager((IPagedList)ViewBag.PagePos, page => Url.Action("Index", new { page, searchString = ViewBag.searchString, searchChoice = ViewBag.searchChoice, sortOrder = ViewBag.sortOrder }))
     </div>
